﻿using System.Text;
using Messenia.GUI.Console.ServiceResolver;
using Messenia.Data;
using System.Reflection;
using Messenia.Data.Interfaces;

namespace Messenia.GUI.Console
{
    class main
    {
        static void Main(string[] args)
        {
            var someCollection = IntefaceResolver.Resolve<IProject>();
            var list = someCollection.GetAll();
            if (list.Count > 0)
            {
                foreach (PropertyInfo p in list[0].GetType().GetProperties())
                {
                    if (p.Name.Length>5)
                        System.Console.Write(p.Name.Substring(0,5) + " ");
                    if (p.Name.Length == 5)
                        System.Console.Write(p.Name + " ");
                    if (p.Name.ToString().Length < 5)
                    {
                        if (p.Name.ToString().Length == 1)
                            System.Console.Write(p.Name + "     ");    
                        if (p.Name.ToString().Length == 2)
                            System.Console.Write(p.Name + "    ");
                        if (p.Name.ToString().Length == 3)
                            System.Console.Write(p.Name + "   ");
                        if (p.Name.ToString().Length == 4)
                            System.Console.Write(p.Name + "  ");    
                    }
                                        
                }
                System.Console.Write(System.Environment.NewLine);
                StringBuilder sb = new StringBuilder();
                foreach (object obj in list)
                {
                    foreach (PropertyInfo p in obj.GetType().GetProperties())
                    {
                        var value = p.GetValue(obj, null);
                        if (value != null)
                        {
                            if (value.ToString().Length > 5)
                                value = value.ToString().Substring(0, 5);
                            if (value.ToString().Length < 5)
                            {
                                if (value.ToString().Length == 1)
                                    value = value.ToString() + "    ";
                                if (value.ToString().Length == 2)
                                    value = value.ToString() + "   ";
                                if (value.ToString().Length == 3)
                                    value = value.ToString() + "  ";
                                if (value.ToString().Length == 4)
                                    value = value.ToString() + " ";
                            }
                        }
                        sb.Append(value+" ");
                    }
                    sb.Append(System.Environment.NewLine);
                }                
                System.Console.Write(sb.ToString());
                
            }
            
            System.Console.ReadLine();
        }
    }
}
